package com.example.demo.sms;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class SmsUtil {

    private static String template = "【新甘肃云】您的验证码为：%s，该验证码%s分钟内有效，请勿泄漏于他人！";
    private static String account = "922696";
    private static String password = "ywTdpUhOOk8AfZ";
    private static String extno = "10690721";

    public static void send(String telephone, String code,int minuteTime) {
        try {
            Map<String,Object> p = new HashMap<String,Object>();
            p.put("account", account);//账号
            p.put("password", password);//密码
            String content = String.format(template, code, minuteTime);
            p.put("mobile", telephone);
            p.put("content",content);
            p.put("extno",extno);//接入码
            SmsHttpApi smsHttpApi = new SmsHttpApi(ApiRequestMethodEnum.get);
            //发短信
            String result = "";
            result = smsHttpApi.doAction(p, SmsActionEnum.send);
            log.info("SmsUtil result:{}",result);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }


    public static void main(String[] args) {
        send("15868854470","666666",5);
//        Map<String,Object> p = new HashMap<String,Object>();
////        p.put("account", "922039");
//////账号  p.put("password", "123456");//密码
////        p.put("mobile", "15868854470");
////        p.put("content","【创信】你的验证码是2386,3分钟内有效！");
////        p.put("extno","10690");
//        p.put("account", "922696");//账号
//        p.put("password", "ywTdpUhOOk8AfZ");//密码
//        p.put("mobile", "15868854470");
//        p.put("content","【新甘肃云】您的验证码为：888888，该验证码5分钟内有效，请勿泄漏于他人！");
//        p.put("extno","10690721");//接入码
//
//
//
//         SmsHttpApi smsHttpApi = new SmsHttpApi(ApiRequestMethodEnum.get);
//        try {
//            //发短信
//            String result = "";
//            System.out.println("发送短信-------------------------------------------");
//            result = smsHttpApi.doAction(p, SmsActionEnum.send);
//            System.out.println(result);
//
//            //查询余额
////            System.out.println("查询余额-------------------------------------------");
////            result = smsHttpApi.doAction(p,SmsActionEnum.overage);
////            System.out.println(result);
////
////            //上行接口(回复)
////            System.out.println("上行接口(回复)-------------------------------------------");
////            result = smsHttpApi.doAction(p,SmsActionEnum.mo);
////            System.out.println(result);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


    }

}
